package com.xing.binbackend.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.xing.binbackend.common.BaseResponse;
import com.xing.binbackend.util.ResultUtils;
import com.xing.binbackend.topology.service.TopologyServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/")
public class MainController {
    @Resource
    private TopologyServiceImpl topologyService;

    /**
     * 健康检查
     * http://localhost:8080/api/health
     */
    @GetMapping("/health")
    public BaseResponse<String> health() {
        return ResultUtils.success("ok");
    }

    @GetMapping("/topo")
    public BaseResponse<String> queryTopology(@RequestParam String ip) throws JsonProcessingException {
        String data = topologyService.queryTopology(ip);
        return ResultUtils.success(data);
    }
}
